The following code installs and loads needed packages
#loads needed packages
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(leaflet)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
The following code creates a plot, using openly-available income information from the U.S. Census’ 2013-2017 American Community Survey 5-year estimates (https://factfinder.census.gov/faces/tableservices/jsf/pages/productview.xhtml?pid=ACS_17_5YR_S2503&prodType=table).
## [1] "This plot shows median locality income and housing costs for all localities in Virginia December 16th, 2018"
#reads in address data obtained from openaddresses.io
dat <- read.csv("JD_ACS_17_5YR_S2503_with_ann.csv")
#creates simple linear regression for trendline
m1 <- lm(dat$housingmedian~dat$medianincome)
#creates plot
plot <- plot_ly(data = dat, x = dat$medianincome, y = dat$housingmedian,
text = dat$geography, type = "scatter")
plot <- add_lines(plot, x = dat$medianincome, y = predict(m1))
plot <- layout(plot, showlegend = FALSE)
plot
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode